package cliente.gui;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import servidor.dominio.*;
import servidor.dominio.Empleado;

import comun.dto.*;


public class GUIModificarEmpleado extends JFrame {

    /** Creates new form GUIModificarEmpleado */
    public GUIModificarEmpleado() {
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    	 jPanel1 = new javax.swing.JPanel();
         jLabel1 = new javax.swing.JLabel();
         opBusqueda = new javax.swing.JComboBox();
         jScrollPane1 = new javax.swing.JScrollPane();
         tablaEmpleados = new javax.swing.JTable();
         jLabel2 = new javax.swing.JLabel();
         cuitEmpresa = new javax.swing.JTextField();
         irCuitEmp = new javax.swing.JButton();
         jLabel3 = new javax.swing.JLabel();
         cuil = new javax.swing.JTextField();
         irCuil = new javax.swing.JButton();
         modificar = new javax.swing.JButton();
         cancelar = new javax.swing.JButton();

         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
         setTitle("Modificar");
  

         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Modificar Empleado"));

         jLabel1.setText("Buscar Empleado Por: ");

         opBusqueda.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cuit Empresa", "Cuil Empleado" }));

         tablaEmpleados.setModel(new javax.swing.table.DefaultTableModel(
             new Object [][] {

             },
             new String [] {
                 "Nombre", "Apellido", "Cuil", "Categoria", "Fecha de Ingreso"
             }
         ) {
             Class[] types = new Class [] {
                 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
             };
             boolean[] canEdit = new boolean [] {
                 true, true, false, true, true
             };

             public Class getColumnClass(int columnIndex) {
                 return types [columnIndex];
             }

             public boolean isCellEditable(int rowIndex, int columnIndex) {
                 return canEdit [columnIndex];
             }
         });
         jScrollPane1.setViewportView(tablaEmpleados);

         jLabel2.setText("Cuit Empresa:");

         irCuitEmp.setText("IR");

         jLabel3.setText("Cuil Empleado:");

         irCuil.setText("IR");

         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
         jPanel1.setLayout(jPanel1Layout);
         jPanel1Layout.setHorizontalGroup(
             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                         .addContainerGap()
                         .addComponent(jLabel1)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(opBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addGap(18, 18, 18)
                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                             .addComponent(jLabel2)
                             .addComponent(jLabel3))
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                             .addComponent(cuil, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                             .addComponent(cuitEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                             .addComponent(irCuil, 0, 0, Short.MAX_VALUE)
                             .addComponent(irCuitEmp, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))))
                 .addGap(37, 37, 37))
         );
         jPanel1Layout.setVerticalGroup(
             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel1)
                     .addComponent(opBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(jLabel2)
                     .addComponent(cuitEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(irCuitEmp))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel3)
                         .addComponent(cuil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                     .addComponent(irCuil))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addContainerGap())
         );

         modificar.setText("Modificar");

         cancelar.setText("Cancelar");

         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                         .addContainerGap()
                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                     .addGroup(layout.createSequentialGroup()
                         .addGap(153, 153, 153)
                         .addComponent(modificar)
                         .addGap(58, 58, 58)
                         .addComponent(cancelar)))
                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(modificar)
                     .addComponent(cancelar))
                 .addContainerGap())
         );

         pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUIModificarEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUIModificarEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUIModificarEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUIModificarEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUIModificarEmpleado().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton cancelar;
    private javax.swing.JTextField cuil;
    private javax.swing.JButton modificar;
    private javax.swing.JTextField cuitEmpresa;
    private javax.swing.JButton irCuil;
    private javax.swing.JButton irCuitEmp;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox opBusqueda;
    private javax.swing.JTable tablaEmpleados;
    // End of variables declaration

    /**
     * @return the Cancelar
     */
    public javax.swing.JButton getCancelar() {
        return cancelar;
    }

    /**
     * @param Cancelar the Cancelar to set
     */
    public void setCancelar(javax.swing.JButton Cancelar) {
        this.cancelar = Cancelar;
    }

    /**
     * @return the Cuil
     */
    public javax.swing.JTextField getCuil() {
        return cuil;
    }

    /**
     * @param Cuil the Cuil to set
     */
    public void setCuil(javax.swing.JTextField cuil) {
        this.cuil = cuil;
    }

    /**
     * @return the Modificar
     */
    public javax.swing.JButton getModificar() {
        return modificar;
    }

    /**
     * @param Modificar the Modificar to set
     */
    public void setModificar(javax.swing.JButton modificar) {
        this.modificar = modificar;
    }

    /**
     * @return the cuitEmpresa
     */
    public javax.swing.JTextField getCuitEmpresa() {
        return cuitEmpresa;
    }

    /**
     * @param cuitEmpresa the cuitEmpresa to set
     */
    public void setCuitEmpresa(javax.swing.JTextField cuitEmpresa) {
        this.cuitEmpresa = cuitEmpresa;
    }

    /**
     * @return the irCuil
     */
    public javax.swing.JButton getIrCuil() {
        return irCuil;
    }

    /**
     * @param irCuil the irCuil to set
     */
    public void setIrCuil(javax.swing.JButton irCuil) {
        this.irCuil = irCuil;
    }

    /**
     * @return the irCuitEmp
     */
    public javax.swing.JButton getIrCuitEmp() {
        return irCuitEmp;
    }

    /**
     * @param irCuitEmp the irCuitEmp to set
     */
    public void setIrCuitEmp(javax.swing.JButton irCuitEmp) {
        this.irCuitEmp = irCuitEmp;
    }

    /**
     * @return the opBusqueda
     */
    public javax.swing.JComboBox getOpBusqueda() {
        return opBusqueda;
    }

    /**
     * @param opBusqueda the opBusqueda to set
     */
    public void setOpBusqueda(javax.swing.JComboBox opBusqueda) {
        this.opBusqueda = opBusqueda;
    }

    /**
     * @return the tablaEmpleados
     */
    public javax.swing.JTable getTablaEmpleados() {
        return tablaEmpleados;
    }

    /**
     * @param tablaEmpleados the tablaEmpleados to set
     */
    public void setTablaEmpleados(javax.swing.JTable tablaEmpleados) {
        this.tablaEmpleados = tablaEmpleados;
    }
    
    public void setTablaEmpleados(java.util.Vector  empleados){
		EmpleadoDTO empl;
		int i=0;
		Object datos[]=new Object[4];
		while (!empleados.isEmpty()){
			DefaultTableModel m=(DefaultTableModel)tablaEmpleados.getModel();
			String[] filavacia=new String[4];
			m.addRow(filavacia);
			empl=(EmpleadoDTO) empleados.get(0);
			tablaEmpleados.setValueAt(empl.getNombre(), i, 0);
			tablaEmpleados.setValueAt(empl.getApellido(), i, 1);
			tablaEmpleados.setValueAt(empl.getCuil(), i, 2);

			tablaEmpleados.setValueAt(empl.getCategoria().getNombre(), i, 3);
			tablaEmpleados.setValueAt(empl.getFechaIngreso(),i,4);

			
			empleados.remove(0);
			i++;
			
		}
	}
    
    public void setTablaEmpleado(Empleado  empleado){
		//EmpleadoDTO empl;
		//int i=0;
		//Object datos[]=new Object[4];
		//while (!empleados.isEmpty()){
			DefaultTableModel m=(DefaultTableModel)tablaEmpleados.getModel();
			String[] filavacia=new String[4];
			m.addRow(filavacia);
			//empl=(EmpleadoDTO) empleados.get(0);
			System.out.println("empleado es "+ empleado.getApellido().isEmpty());
			tablaEmpleados.setValueAt(empleado.getNombre(), 0, 0);
			tablaEmpleados.setValueAt(empleado.getApellido(), 0, 1);
			tablaEmpleados.setValueAt(empleado.getCuil(), 0, 2);

			tablaEmpleados.setValueAt(empleado.getCategoria().getNombre(), 0, 3);
			tablaEmpleados.setValueAt(empleado.getFechaIngreso(),0,4);

			
			//empleados.remove(0);
			//i++;
			
	//	}
	}
    
	public void setTablaEmpleado(){
		tablaEmpleados.setModel(new javax.swing.table.DefaultTableModel(
				new Object [][] {
					
				},
				new String [] {
						"Nombre","Apellido", "Cuil", "Categoria", "Fecha de Ingreso"
				}
				));
	}
    
    public String getNombEmpleado(int fila){
    	return tablaEmpleados.getValueAt(fila, 0).toString();
    	
    }
    
    public String getApeEmpleado(int fila){
    	return tablaEmpleados.getValueAt(fila, 1).toString();
    	
    }
    
    public String getCuilEmpleado(int fila){
    	return tablaEmpleados.getValueAt(fila, 2).toString();
    	
    }
    
    public Categoria getCatEmpleado(int fila){
    	return (Categoria)tablaEmpleados.getValueAt(fila, 3); 
    	
    }
    
    public String getFecIngEmpleado(int fila){
    	return tablaEmpleados.getValueAt(fila, 4).toString();
    	
    }
    
    
    public void setActionListeners(ActionListener lis) {
        modificar.addActionListener(lis);
        cancelar.addActionListener(lis);
        opBusqueda.addActionListener(lis);
        irCuil.addActionListener(lis);
        irCuitEmp.addActionListener(lis);
    }
}

